// Quarto.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Game.h"


void getIPandPort(std::string s, char* ipAddress, int* portNo);

int _tmain(int argc, _TCHAR* argv[])
{
	enum startupMode{Tournament, Demo};
	std::cout << "Welcome! Select the startup mode (0 for Tournament Settings, 1 for Demo Settings):" << std::endl;
	int number;
	while(std::cin >> number) if(number == 0 || number==1) break;
	if(number == 1) Game::start();
	else{
		std::cout << "Enter IP Address and Port number (xxx.xxx.xxx.xxx:pppp)" << std::endl;
		std::string input;
		std::cin >> input;
		char ipAddress[100];
		int portNumber = 0;
		getIPandPort(input, ipAddress, &portNumber);
		Game::tournamentStart(ipAddress, portNumber);
	}
	return 0;
}

void getIPandPort(std::string s, char* ipAddress, int* portNo)
{
	char result[16];
	int i;
	for(i = 0; s[i] != ':'; ++i) ipAddress[i] = s[i];
	ipAddress[i+1] = '\0';
	*portNo = (s[++i]-'0')*1000 + (s[i+1]-'0')*100 + (s[i+2]-'0')*10 + (s[i+3]-'0');
}

int getPortNumber(std::string s)
{
	return (s[16] -'0')*1000 + (s[17] -'0')*100 + (s[18] -'0')*10 + (s[19] -'0');
}

